package wtws.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertyManager {

	public static JobConfig loadProperty(InputStream file) {
		JobConfig jobConf = new JobConfig();
		Properties prop = new Properties();
		try {
			prop.load(file);
		} catch (IOException e) {
			e.printStackTrace();
		}

		if (prop.getProperty("FTP_USER") != null) {
			jobConf.setFtpUser(prop.getProperty("FTP_USER"));
		}
		if (prop.getProperty("FTP_URL") != null) {
			jobConf.setFtpUrl(prop.getProperty("FTP_URL"));
		}
		if (prop.getProperty("FTP_PASSWD") != null) {
			jobConf.setFtpPasswd(prop.getProperty("FTP_PASSWD"));
		}
		if (prop.getProperty("FTP_PATH") != null) {
			jobConf.setFtpPath(prop.getProperty("FTP_PATH"));
		}
		if (prop.getProperty("IN_FQZ") != null) {
			jobConf.setInFreq(Integer.parseInt(prop.getProperty("IN_FQZ")));
		}
		if (prop.getProperty("MSG_FILENAME") != null) {
			jobConf.setMsgFilename(prop.getProperty("MSG_FILENAME"));
		}
		if (prop.getProperty("MSG_IN_DIR") != null) {
			jobConf.setMsgInDir(prop.getProperty("MSG_IN_DIR"));
		}
		if (prop.getProperty("FTP_PATH_PRECIP") != null) {
			jobConf.setFtpPrecipPath(prop.getProperty("FTP_PATH_PRECIP"));
		}
		return jobConf;
	}
}
